﻿using System.Web;
using System.Web.Http;

namespace MainService.Controllers.Extend
{
    /// <summary>
    /// 基础WebApi控制器
    /// </summary>
    public class BaseApiController : ApiController
    {
        private HttpRequestBase _requestBase;

        /// <summary>
        /// 传统RequestBase
        /// </summary>
        protected HttpRequestBase RequestBase
        {
            get
            {
                if (_requestBase == null)
                {
                    _requestBase = GetRequest();
                }
                return _requestBase;
            }
        }

        #region 私有方法
        /// <summary>
        /// 获取RequestBase
        /// </summary>
        /// <returns></returns>
        private HttpRequestBase GetRequest()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context
            HttpRequestBase request = context.Request;//定义传统request对象
            return request;
        }
        #endregion
    }
}